/*
 * main.cpp
 *
 *  Created on: 2013-1-23
 *      Author: heqiu
 */

#include "Guud.h"
#include "Global.h"
using namespace guud;

int main(int argc, char ** argv) {
	g_GlobalData.m_GuudLog.setLogName("./log_farm.txt");
	g_GlobalData.m_GuudLog.delfile();
	g_GlobalData.m_GuudLog.log("[%s][%d]游戏开始", __FILE__, __LINE__);
	bool bFlag = guud_init();
	if (!bFlag) {
		g_GlobalData.m_GuudLog.log("[%s][%d]错误:guud_init 失败", __FILE__,
				__LINE__);
		exit(-1);
	}
	//加载全局配置
	bFlag = g_GlobalData.m_config_game.loadFile("./conf/game.xml");
	if (!bFlag) {
		g_GlobalData.m_GuudLog.log("[%s][%d]错误:加载全局配置失败", __FILE__, __LINE__);
		exit(-1);
	}
	//加载字体
	bFlag = g_GlobalData.m_GuudFont.init("lazy.ttf", 10);
	if (!bFlag) {
		g_GlobalData.m_GuudLog.log("[%s][%d]错误:加载字体失败", __FILE__, __LINE__);
		exit(-1);
	}
	//创建屏幕
	g_GlobalData.m_pGuudScreen = new GuudScreen(
			g_GlobalData.m_config_game.getKKValueInt32("screen", "width-pixel"),
			g_GlobalData.m_config_game.getKKValueInt32("screen",
					"height-pixel"));
	g_GlobalData.m_pGuudScreen->setCaption(
			g_GlobalData.m_config_game.getKKValueStr("screen", "caption").c_str());

	//创建第一场景,作为游戏的开机选择
	GuudCanvas * pGuudCanvas = new CanvasWelcome(0, 0, 0);
	pGuudCanvas->init();
	g_GlobalData.m_pGuudCanvasWelcome = pGuudCanvas;

	//启动绘图场景
	g_GlobalData.m_GameDrawThread.start();
	g_GlobalData.m_GameListener.beginListen();
	g_GlobalData.m_GameDrawThread.stop();
	g_GlobalData.m_GameDrawThread.wait();
	g_GlobalData.m_GuudLog.log(
			"[%s][%d]----------------------------游戏结束----------------------------",
			__FILE__, __LINE__);
	return 0;
}

